package com.example.friend.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.example.friend.pojo.User;


@WebServlet("/index")
public class IndexServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	
		resp.setContentType("text/html;charset=utf-8");
		PrintWriter pw = resp.getWriter();
		pw.print("首页<br />");
		
		// 得到会话
		HttpSession session = req.getSession();
		User u = (User)session.getAttribute("user");
		System.out.println("user:"+u);
		
		if(u!=null)
		{
			pw.print("欢迎光临:"+u.getAge()+"岁"+"的"+u.getUsername()+"<br />");
			pw.print("<a href='logout'>登出</a>");
			
		}
		else
		{
			pw.print("欢迎光临:游客 <br />");
			pw.print("<a href='login.html'>登录</a>");
		}
		
		
		
	
	
	}
	
}